<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<?
session_start();
require_once '../Negocio/CsSolicitante.php';
require_once '../Negocio/CsEmpleado.php';
require_once '../Negocio/CsCaso.php';
require_once '../Negocio/CsCliente.php';
require_once '../Negocio/CsEstado.php';

function Guardar()
{
    if($_SESSION['rl'] ==4){
        $idper=$_SESSION['ident'];
    }
    else {
        $idper=$_POST['t_isolicitante'];
    }
    $caso = new CsCaso();
    $caso->dato[1]=date("Y-n-j H:i:s");
    $caso->dato[2]=$_POST['t_problema'];
    $caso->dato[3]=$idper;
    $caso->dato[4]=1;
   $trans= $caso->GuardarDato($caso);
     if($trans == 0)
               echo"ERROR AL GUARDAR...!!!";
           else {
               echo"REGISTRO GUARDADO...!!!";
                }
}

function  traerllave(){
        $caso = new CsCaso();
        $ds =$caso->Llave();
        $vec=  mysql_fetch_array($ds);
        $nro = $vec[0] +1;
        echo "Nro. de Caso :".$nro;
}

if($_POST['c_cliente']=="cliente") {
    $_SESSION['cliente']= $_POST['t_cliente'];
    $_SESSION['icliente']= $_POST['t_icliente'];
}

//if($_POST['c_solicitante']=="solicitante") {
//   $_SESSION['isolicitante']= $_POST['t_idensolicitante']; 
//}
    
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
      
        <form name="f_apcaso" method="post" action="">
        <table width="600" height="100" border="0" align="center" bgcolor="#808080">
            <tr>
                <td width="70" height="50" colspan="2"><div class="SubTitulo">Apertura de Caso:</div></td>
                <td><div class="textointerno" align="right">Fecha:<input type="date" name="d_fecha" value="<? echo date("Y-n-j"); ?>" disabled size="10"></div></td>
            </tr>
            <?
            if($_SESSION['rl'] ==4){
                $solicitante = new CsSolicitante();
                $solicitante->dato[0] = $_SESSION['ident'];
                $ds = $solicitante->Identidad();
                $vec = mysql_fetch_array($ds);
                if($vec != NULL){?>
            <tr>
                <td width='250'><div class='textointerno'>Empresa Cliente:</div></td>
                <td width='348' colspan='2'><input name='t_cliente' type='text' size='35' disabled value='<? echo $vec[1]; ?>'></td>
            </tr>
            <tr>
                <td width='250'><div class='textointerno'>Solicitante:</div></td>
                <td width='348' colspan='2'><input name='t_solicitante' type='text' size='30' disabled value='<? echo $_SESSION['nombre']; ?>'></td>
            </tr>
            <tr>
                <td width='250'><div class='textointerno'>Cargo:</div></td>
                <td width='348' colspan='2'><input name='t_cargo' type='text' size='25' disabled value='<? echo $vec[0]; ?>'></td>
            </tr><?}
            }  else {    ?>
            <tr>
                <td width='200'><div class='textointerno'>Empresa Cliente:</div></td>
                <td width='398' colspan='2'>
                    <form name='buscar_cliente' method='post' action=''>
                    <input name='t_bcliente' type='text' size='35' value='<?  echo $_SESSION['cliente'] ?>'>&nbsp;&nbsp;&nbsp;
                    <input type='hidden'name='c_bcliente' value='buscar_cliente'>
                    <input type='image' src='../imagenes/buscar.gif' name='b_buscarcli' value='Buscar Cliente'>
                    </form>
                </td>
            </tr>
            <? if($_POST['c_bcliente']=="buscar_cliente") { ?>
            <tr>
                <td width='200' ></td>
                <td width='348' colspan="2">
                    <? $cliente = new CsCliente();
                       $cliente->dato[0] = $_POST['t_bcliente'];
                       $ds = $cliente->TraerDatos();?>
                    <table width="346" border="0" align="left" bgcolor="#fff">
                        <?
                            while ($vec = mysql_fetch_array($ds)){?>
                        <tr>
                            <td><form name='buscar_cliente1' method='post' acction=''>
                                <input type='hidden'name='t_icliente' value='<? echo $vec[0]; ?>'>
                                <input type='hidden'name='t_cliente' value='<? echo $vec[2]; ?>'>
                                <input type='hidden'name='c_cliente' value='cliente'>
                                <input type='submit' name='b_cliente' class='enlace' value='<? echo $vec[2]; ?>'>
                            </form></td>
                        </tr><?} 
                        ?>
                    </table>
                </td>
            </tr><?}?> 
            <tr>
                <td width='200'><div class='textointerno'>Solicitante :</div></td>
                <td width='398' colspan='2'>
                    <form name='buscar_solicitante' method='post' action=''>
                    <input name='t_solicitante' type='text' size='30' value='<?  echo $_POST['b_solicitante']; ?>'>&nbsp;&nbsp;&nbsp;
                    <input type='hidden'name='c_bsolicitante' value='buscar_solicitante'>
                    <input type='image' src='../imagenes/buscar.gif' name='b_buscarcli' value='Buscar Cliente'>
                    </form>
                </td>
            </tr>
            <? if($_POST['c_bsolicitante']=="buscar_solicitante") { ?>
            <tr>
                <td width='200' ></td>
                <td width='348' colspan="2">
                    <?
                       $solicitante = new CsSolicitante();
                       $solicitante->dato[0] = $_SESSION['icliente'];
                       $solicitante->dato[1] = $_POST['t_solicitante'];
                       $ds = $solicitante->SolicitantexCliente()?>
                    <table width="346" border="0" align="left" bgcolor="#fff">
                        <?
                            while ($vec = mysql_fetch_array($ds)){?>
                        <tr>
                            <td>
                                <form name='buscar_solicitante1' method='post' acction=''>
                                <input type='hidden'name='t_idensolicitante' value='<? echo $vec[0]; ?>'>
                                <input type='hidden'name='t_cargo' value='<? echo $vec[2]; ?>'>
                                <input type='hidden'name='c_solicitante' value='solitante'>
                                <input type='submit' name='b_solicitante' class='enlace' value='<? echo $vec[1]; ?>'>
                            </form></td>
                        </tr><?} ?>
                    </table>
                </td>
            </tr><? } ?>
            <tr>
                <td width='200'><div class='textointerno'>Cargo:</div></td>
                <td width='398' colspan='2'>
                    <input type='hidden'name='t_isolicitante' value='<?  echo $_POST['t_idensolicitante']; ?>'>
                    <input name='t_cargo' type='text' size='25' value='<?  echo $_POST['t_cargo']; ?>' disabled ></td>
            </tr>
           <? }
            ?>
            <tr>
                <td width="200" valign="top"><div class="textointerno">Descripci&oacute;n del Problema:</div></td>
                <td width="398" colspan="2"><textarea name="t_problema" style="width: 400px; height: 100px;"></textarea></td>
            </tr>
            <tr>
                 <td width="200"><div align="left" class="textointerno">
                   <?
                   if($_POST['baper']=="Aperturar Caso") 
                   {
                    traerllave();
                   }
                   ?>  
                     </div>
                 </td>
                <td width="200"><div align="center"><input type="submit" name="baper" value="Aperturar Caso"></div></td>
                 <td width="200"><div align="center"></div></td>
            </tr>
        </table>
        </form>
        <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <?
            if ($_POST['baper']=="Aperturar Caso") { ?>
            <table width="600" height="30" border="0" align="center" bgcolor="	#90ee90">
                <tr>
                    <td><div align="center">
                        <? Guardar(); 
                            echo "<meta content='3;URL=principal.php?pg=apertura' http-equiv='REFRESH'> </meta>";
                            $_SESSION['cliente'] = null;
                            $_SESSION['icliente'] = null;
                        ?>
                    </div></td>
                </tr>
            </table>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
        <? } ?>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
    </body>
</html>
